package fightplan.ui;

public class TwoLineStringSplitter {

	public static String split(String s) {
		if (s == null || s.length() < 5)
			return s;

		int pos = s.length() / 2 + 1;

		int search = 1;
		while (true) {
			if (pos < 0)
				return s;
			if (Character.isWhitespace(s.charAt(pos)))
				break;

			pos += search;
			if (pos >= s.length())
				return s;
			if (Character.isWhitespace(s.charAt(pos)))
				break;

			search *= 2;
			pos -= search;
		}

		return "<HTML>" + s.substring(0, pos).replace(" ", "&nbsp;") + "<BR>"
				+ s.substring(pos + 1, s.length()).replace(" ", "&nbsp;") + "</HTML>";
	}

}
